﻿@page "/system_tool/code_gen"
@using Gardener.CodeGeneration.Resources;
@inherits ListOperateTableBase<CodeGenDto, Guid, CodeGenEdit,CodeGenLocalResource>

<div>
    <Table @ref="_table"
           TItem="CodeGenDto"
           DataSource="@_datas"
           Total="_total"
           OnChange="@OnChange"
           @bind-PageIndex="_pageIndex"
           @bind-PageSize="_pageSize"
           @bind-SelectedRows="_selectedRows"
           Loading="@_tableLoading.Value"
           Context="model"
           RemoteDataSource>
        <TitleTemplate>
            <TableSearch TDto="CodeGenSearchDto" OnSearch="DoSearch" DefaultValue="_defaultSearchValue" CustomLocalizer="Localizer" AlwaysShowSearchButton="true"></TableSearch>
            @*Custom Search*@
            <Row>
                <AntDesign.Col Span="24">
                    <Space>
                        <SpaceItem>
                            <span>@Localizer[CodeGenLocalResource.TableName]: </span>
                            <Select Mode="multiple"
                                    DataSource="@_select_TableName"
                                    @bind-Values="@_searchDto.TableName"
                                    ValueName="@nameof(SelectItem.ValueName)"
                                    LabelName="@nameof(SelectItem.LabelName)"
                                    TItem="SelectItem"
                                    TItemValue="string"
                                        EnableSearch
                                        AllowClear
                                    Style="width:200px">
                            </Select>
                            </SpaceItem>
                            <SpaceItem>
                            <span>@Localizer[CodeGenLocalResource.ClassName]: </span>
                            <Input Style="@searchInputStyle" Type="text" TValue="string" OnPressEnter="DoSearch"
                                   @bind-Value="@_searchDto.ClassName"></Input>
                            </SpaceItem>
                            </Space>
                            </AntDesign.Col>
                            </Row>
                            <Row>
                            <AntDesign.Col Span="8">
                            <Button Type="@ButtonType.Primary" Icon="delete" Danger OnClick="OnClickDeletes" Loading="_deletesBtnLoading">
                        @Localizer[SharedLocalResource.DeleteSelected]
                    </Button>
                    <Button Type="@ButtonType.Primary" Icon="code" OnClick="OnClickGenerates" Loading="_generatesBtnLoading">
                        @Localizer[CodeGenLocalResource.BatchGenerate]
                    </Button>
                    </AntDesign.Col>
                    <AntDesign.Col Span="16" Style="text-align:right">
                    <Space>
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="plus" OnClick="OnClickAdd">
                                @Localizer[SharedLocalResource.Add]
                            </Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="reload" OnClick="ReLoadTable">
                                @Localizer[SharedLocalResource.Refresh]
                            </Button>
                        </SpaceItem>

                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="folder" OnClick="OpenCodeGenFolder">
                                @Localizer[CodeGenLocalResource.OpenCodeGenFolder]
                            </Button>
                        </SpaceItem>

                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="download" OnClick="OnClickShowSeedData">
                                @Localizer[SharedLocalResource.SeedData]
                            </Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="download" OnClick="OnDownloadConfigSeedDataClick">
                                @(Localizer.Combination(SharedLocalResource.Settings, SharedLocalResource.SeedData))
                            </Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Button Icon="info-circle" OnClick="ShowHelp">
                                说明
                            </Button>
                        </SpaceItem>
                    </Space>
                </AntDesign.Col>
            </Row>

        </TitleTemplate>
        <ColumnDefinitions>
            <Selection Key="@(model.Id.ToString())" />
            <Column @bind-Field="@model.TableName" Title="@(Localizer[CodeGenLocalResource.TableName])" Sortable Filterable />
            <Column @bind-Field="@model.ClassName" Title="@(Localizer[CodeGenLocalResource.ClassName])" Sortable Filterable />
            <Column @bind-Field="@model.Module" Title="@(Localizer[CodeGenLocalResource.Module])" Sortable Filterable />
            <Column @bind-Field="@model.Remark" Title="@(Localizer[CodeGenLocalResource.Remark])" Sortable Filterable></Column>
            <Column @bind-Field="@model.MenuNameEN" Title="@(Localizer.Combination(CodeGenLocalResource.MenuName,"(",SharedLocalResource.EN,")"))" Sortable Filterable />
            <Column @bind-Field="@model.MenuNameCH" Title="@(Localizer.Combination(CodeGenLocalResource.MenuName,"(",SharedLocalResource.CH,")"))" Sortable Filterable />
            <Column @bind-Field="@model.TableDescriptionEN" Title="@(Localizer.Combination(CodeGenLocalResource.TableDescription,"(",SharedLocalResource.EN,")"))" Sortable Filterable />
            <Column @bind-Field="@model.TableDescriptionCH" Title="@(Localizer.Combination(CodeGenLocalResource.TableDescription,"(",SharedLocalResource.CH,")"))" Sortable Filterable />
            <Column @bind-Field="@model.CreatedTime" Title="@(Localizer[CodeGenLocalResource.CreatedTime])" Format="@ClientConstant.DateTimeFormat" Sortable DefaultSortOrder="@SortDirection.Descending" />
            <ActionColumn Title="@Localizer[SharedLocalResource.Action]" Fixed="right">
                <Space>
                    <SpaceItem>
                        <Button Type="@ButtonType.Link" OnClick="()=>OnClickEdit(model.Id)">
                            @Localizer[SharedLocalResource.Edit]
                        </Button>
                    </SpaceItem>
                    <SpaceItem>
                        <Button Type="@ButtonType.Link" OnClick="()=>OnClickConfigure(model.Id)">
                            @Localizer[SharedLocalResource.Setting]
                        </Button>
                    </SpaceItem>

                    <SpaceItem>
                        <Button Type="@ButtonType.Link" Icon="menu" OnClick="()=>OnClickGenerateMenu(model.Id)">
                            @Localizer[CodeGenLocalResource.GenerateMenu]
                        </Button>
                    </SpaceItem>

                    @*<SpaceItem>
                    <Button Type="@ButtonType.Link" Icon="global" OnClick="()=>OnClickGenerateLocale(model.Id)" Loading="_generatesBtnLoading">
                    @localizer["GenerateLocale"]
                    </Button>
                    </SpaceItem>*@

                    <SpaceItem>
                        <Button Type="@ButtonType.Link" Icon="code" OnClick="()=>OnClickGenerate(model.Id)">
                            @Localizer[SharedLocalResource.Generate]
                        </Button>
                    </SpaceItem>

                    <SpaceItem>
                        <Button Type="@ButtonType.Link" Danger OnClick="()=>OnClickTrueDelete(model.Id)">
                            @Localizer[SharedLocalResource.Delete]
                        </Button>
                        </SpaceItem>
                        </Space>
                        </ActionColumn>
                    </ColumnDefinitions>
                    </Table>
                </div>
